package com.atcjx.exception.excetionHandler;

import com.atcjx.MyUtils.ResultFactory;
import com.atcjx.exception.UserException;
import com.atcjx.pojo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName UserExceptionHandler.java
 * @Description TODO
 * @createTime 2021年09月26日 20:21:00
 */
@ControllerAdvice
public class UserExceptionHandler {
    @ResponseBody
    @ExceptionHandler(value = UserException.class)
    public Result userExceptionHandler(UserException exception){
        int code = exception.getCode();
        String s = Integer.toString(code);
        String msg = exception.getMsg();
        System.out.println(exception.getCode());
        System.out.println(exception.getMsg());
        return ResultFactory.failure(s,msg);
    }
}
